export function lengthOfLongestSubstring(s: string): number {
    let left = 0;
    let right = 0;
    const charSet = new Set<string>();
    let len = 0

    while (right < s.length) {
        const rightChar = s[right];
        if (charSet.has(rightChar)) {
            // 如果已经有了该字符，则左指针向右移动
            while (charSet.has(rightChar)) {
                const leftChar = s[left];
                charSet.delete(leftChar);
                left++;
            }
        }
        // 最后都要把右指针加进来
        charSet.add(rightChar);

        right++;
        len = Math.max(len, right - left);
    }

    return len;
};